#include "loginform.h"
#include "ui_loginform.h"



#include <QGridLayout>
#include "setwsdialog.h"
#include <QDebug>
#include <QShortcut>
#include <QMessageBox>

#include <QDesktopServices>
#include <QUrl>
LoginForm::LoginForm(QWidget *parent) :
    MoveableFramelessDialgo(parent),
    ui(new Ui::LoginForm)
{
    ui->setupUi(this);

    setTabOrder(ui->lineEdit_un,ui->lineEdit_pass);
    setTabOrder(ui->lineEdit_pass,ui->checkBox);
    setTabOrder(ui->checkBox,ui->checkBox_2);
    setTabOrder(ui->checkBox_2,ui->pushButton_login);

    //关闭
    connect(ui->pushButton_close,SIGNAL(clicked()),this,SLOT(doClose()));
    connect(ui->pushButton_setWS,SIGNAL(clicked()),this,SLOT(doSetWS()));
    //关联登录按钮点击
    QShortcut *key=new QShortcut(QKeySequence(Qt::Key_Return),this);//创建一个快捷键"Key_Return"键
    connect(key,SIGNAL(activated()),this,SLOT(doLoginButClick()));//连接到指定槽函数
    key=new QShortcut(QKeySequence(Qt::Key_Enter),this);//创建一个快捷键"Key_Return"键
    connect(key,SIGNAL(activated()),this,SLOT(doLoginButClick()));//连接到指定槽函数
    connect(ui->pushButton_login,SIGNAL(clicked()),this,SLOT(doLoginButClick()));
    connect(ui->label_1,SIGNAL(clicked()),this,SLOT(doRegUser()));
}

LoginForm::~LoginForm()
{
    delete ui;
}

QWidget *LoginForm::getDragnWidget()
{
    return ui->login_top_widget;
}



void LoginForm::doLoginButClick()
{
    if((ui->lineEdit_un->text().size()>0)&&(ui->lineEdit_pass->text().size()))
    accept();
    else
        QMessageBox::about(this,"不能为空","登录帐户和密码不可为空！！！");
}
void LoginForm::doClose()
{
    this->close();
}
void LoginForm::doRegUser()
{
    /*
    DialogRegUser dialogReg;
    dialogReg.setWindowTitle("注册帐号");
    dialogReg.exec();*/
    QDesktopServices::openUrl(QUrl(QLatin1String("http://127.0.0.1")));
}

void LoginForm::doSetWS()
{

    setWSDialog sdialog;
    sdialog.setWindowTitle("服务器参数");
    sdialog.setWS(m_ip,m_port);
    if(sdialog.exec())
    {
        m_ip=sdialog.getWS_ip();
        m_port=sdialog.getWS_port();
    }
}
QString LoginForm::getLoginname()
{
    return ui->lineEdit_un->text();
}
QString LoginForm::getip()
{
    return m_ip;
}
int LoginForm::getport()
{
    return m_port;
}
void LoginForm::setNetarg(QString ip, int port)
{
    m_ip=ip;
    m_port=port;
}
QString LoginForm::getPassword()
{
    return ui->lineEdit_pass->text();
}
